package com.qdsgjsfk.vision.util;

import com.clj.fastble.BleManager;
import com.clj.fastble.callback.BleWriteCallback;
import com.clj.fastble.exception.BleException;
import com.qdsgjsfk.vision.base.BaseApplication;

import jz.joyoung.robot.util.LogUtil;

/**
 * @time 2020/12/17 11:21
 * Created by lbj on 2020/12/17 11:21.
 */
public class FastBleLibUtil {
    public static void write(String sendData, String uuid_service, String uuid_write) {
        BleManager.getInstance().write(
                BaseApplication.currentBleDevice,
                uuid_service, uuid_write,
                sendData.getBytes(),
                new BleWriteCallback() {
                    @Override
                    public void onWriteSuccess(int current, int total, byte[] justWrite) {
                        // 发送数据到设备成功（分包发送的情况下，可以通过方法中返回的参数可以查看发送进度）
                        LogUtil.e( "发送数据成功---" + "onWriteSuccess" );
                    }

                    @Override
                    public void onWriteFailure(BleException exception) {
                        // 发送数据到设备失败
                        System.out.println( exception.getDescription() );
                    }
                } );
    }

    /**
     * 向美沃设备发送第2条指令
     * Created by lbj on 2022/11/5 9:51
     */
    public static void writeTwo(String sendData, String uuid_service, String uuid_write) {
        BleManager.getInstance().write(
                BaseApplication.currentBleDevice,
                uuid_service, uuid_write,
                sendData.getBytes(),
                new BleWriteCallback() {
                    @Override
                    public void onWriteSuccess(int current, int total, byte[] justWrite) {
                        // 发送数据到设备成功（分包发送的情况下，可以通过方法中返回的参数可以查看发送进度）
                        LogUtil.e( "发送数据成功---" + "onWriteSuccess" );
                    }

                    @Override
                    public void onWriteFailure(BleException exception) {
                        // 发送数据到设备失败
                        System.out.println( exception.getDescription() );
                    }
                } );
    }
}
